import { useEffect, useState } from 'react';
import { Row, Col } from 'antd';
import ReactEcharts from 'echarts-for-react';
import { MonthSales } from '@/service/restaurant';

const BingEch = (props: MonthSales) => {
  // 配置对象
  const getOption = () => {
    if (!props.dishList || props.dishList.length === 0) {
      return <>数据为空</>;
    }
    const convertedData = props.dishList.map((item: any) => ({
      name: item.name,
      value: item.num,
    }));
    return {
      tooltip: {
        trigger: 'item',
        formatter: '{a} <br/>{b} : {c} ({d}%)',
      },
      legend: {
        orient: 'vertical',
        left: 'left',
        textStyle: {
          fontSize: 13,
          color: '#FFFFFF',
        },
        data: convertedData,
      },
      series: [
        {
          name: '菜名',
          type: 'pie',
          radius: '55%',
          center: ['50%', '60%'],
          data: convertedData,
          itemStyle: {
            emphasis: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)',
            },
          },
        },
      ],
    };
  };
  return (
    <div>
      <Row gutter={24}>
        <Col span={24}>
          <ReactEcharts option={getOption()} style={{ marginTop: '30px' }} />
        </Col>
      </Row>
    </div>
  );
};

export default BingEch;
